﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Game
{
    /*-------------------------------------------------------------------------
    | Scene:
    | ------------
    | Basic Scene
    |---------------------------------------------------------------------------*/
    public class Scene
    {
        public ISceneTriggerEventSystem TriggerEventSystem
        {
            get;
            set;
        }

        public ISceneHitEventSystem HitEventSystem
        {
            get;
            set;
        }

        private CommonAction.ActionManager mActionManager;

        public List<IManager> Managers = new List<IManager>();

        public IDK.Renderer Renderer
        {
            get;
            set;
        }
        
        public IDK.Core Core
        {
            get;
            set;
        }

        public IDK.Engine Engine
        {
            get;
            set;
        }

        public Scene(IDK.Engine engine)
        {
            Log.Hint("Scene Create");

            //init internal property
            Pause = false;

            Renderer = engine.GetRenderer();
            Core = engine.GetCore();
            Engine = engine;
        }
        
        public CommonAction.ActionManager ActionManager 
        { 
            get { return mActionManager; }
            set { mActionManager = value; }
        }

        internal T AddManager<T>(T manager) where T : IManager
        {
            Managers.Add(manager);
            return manager;
        }

        public T GetManager<T>() where T : IManager
        {
            foreach (IManager it in Managers)
            {
                if (it is T)
                {
                    //WTF : TODO need using "as"
                    return (T)it;
                }
            }
            throw new NullReferenceException("Not found manager");
        }

        public virtual void OnUpdate(Events.ProcessSceneUpdate evnt)
        {
            foreach (IManager it in Managers)
            {
                it.Update(evnt);
            }
        }

        public bool Pause
        {
            get;
            set;
        }
    }
}
